package likou.offer;

public class _48_niubi {
    public static void main(String[] args) {
        System.out.println(lengthOfLongestSubstring("aabaab!bb"));
    }
    //滑动窗口
    public static int lengthOfLongestSubstring(String s) {
        if(s==null||s.isEmpty()) {
            return 0;
        }
        char[] cs = s.toCharArray();
        int[] cMap = new int[128];
        int l = 0, r = 0;
        int ans = 0;
        while(r < cs.length){
            if(cMap[cs[r]] <= l) {
                ans = Math.max(r-l+1,ans);
            } else {
                l = cMap[cs[r]];
            }
            cMap[cs[r]] = r+1;
            ++r;
        }
        return ans;
    }
}
